#include "RenderScene.h"

#include "PreRenderSceneNodes.h"
#include "PreRenderScene.h"
#include "Render/Mesh/RenderMesh.h"
#include "Render/Material/RenderMaterial.h"
#include "Render/PreRenderContext.h"

void CRenderScene::AddAmbientLight(const SColor &InAmbientLight, float InIntensity)
{
    AmbientLights+=InAmbientLight*InIntensity;
}

void CRenderScene::GeneratePreRenderScene(SPreRenderContext& InPreRenderContext,CPreRenderScene* VulkanScene)
{
    for (auto& PointLight : PointLights)
    {
        SPreRenderPointLight& VulkanPointLight=VulkanScene->PointLights.Emplace();
        VulkanPointLight.Position = PointLight.Position;
        VulkanPointLight.Color = PointLight.Color;
        VulkanPointLight.Intensity = PointLight.Intensity;
        VulkanPointLight.Radius = PointLight.Radius;
        VulkanPointLight.ShadowBias = PointLight.ShadowBias;
    }
    for (auto& SpotLight : SpotLights)
    {
        SPreRenderSpotLight& VulkanSpotLight=VulkanScene->SpotLights.Emplace();
        VulkanSpotLight.Position = SpotLight.Position;
        VulkanSpotLight.Color = SpotLight.Color;
        VulkanSpotLight.Intensity = SpotLight.Intensity;
        VulkanSpotLight.Radius = SpotLight.Radius;
        VulkanSpotLight.ShadowBias = SpotLight.ShadowBias;
        VulkanSpotLight.Rotation = SpotLight.Rotation;
        VulkanSpotLight.ConeAngle = SpotLight.ConeAngle;
    }
    for (auto& DirectionalLight : DirectionalLights)
    {
        SPreRenderDirectionalLight& VulkanDirectionalLight=VulkanScene->DirectionalLights.Emplace();
        VulkanDirectionalLight.Rotation = DirectionalLight.Rotation;
        VulkanDirectionalLight.Color = DirectionalLight.Color;
        VulkanDirectionalLight.Intensity = DirectionalLight.Intensity;
    }
    for (auto& MeshInstance : MeshInstances)
    {
        SPreRenderMeshInstance& PreRenderMeshInstance=VulkanScene->MeshInstances.Emplace();
        PreRenderMeshInstance.Position = MeshInstance.Position;
        PreRenderMeshInstance.Rotation = MeshInstance.Rotation;
        PreRenderMeshInstance.Scale = MeshInstance.Scale;
        PreRenderMeshInstance.BoundingSphereRadius = MeshInstance.BoundingSphereRadius;
        for(auto & MeshSection: MeshInstance.MeshSections)
        {
            PreRenderMeshInstance.MeshSections.Add(
                InPreRenderContext.PreRender(MeshSection)
            );
        }

        for(auto & Material: MeshInstance.Materials)
        {
            PreRenderMeshInstance.Materials.Add(
                InPreRenderContext.PreRender(Material)
            );
        }

        PreRenderMeshInstance.CastShadow = MeshInstance.CastShadow;

    }
    VulkanScene->AmbientLights = AmbientLights;
}